<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('信用评价任务计划列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>年份：</label>
                                <input type="text" placeholder="请选择年份" name="taskYear" data-type="date" data-format="yyyy"/>
                            </li>
                            <li>
                                <label>任务名称：</label>
                                <input type="text" name="taskName"/>
                            </li>
                            <li>
                                <label>收支类别：</label>
                                <select name="contractClass" th:with="type=${@dict.getType('contract_class')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>合同类型：</label>
                                <select name="contractType" th:with="type=${@dict.getType('contract_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('task_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="credit:task:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="credit:task:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="credit:task:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="credit:task:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('credit:task:edit')}]];
        var removeFlag = [[${@permission.hasPermi('credit:task:remove')}]];
        var contractClassDatas = [[${@dict.getType('contract_class')}]];
        var contractTypeDatas = [[${@dict.getType('contract_type')}]];
        var statusDatas = [[${@dict.getType('task_status')}]];
        var prefix = ctx + "credit/task";

        //日期控件
        $("input[name='taskYear']").datetimepicker({
            language:'zh-cn',
            format: 'yyyy',
            autoclose: true,
            todayBtn: false,
            todayHighlight: true,
            startView: 'decade',
            minView:'decade',
            maxView:'decade',
        });

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "信用评价计划",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'taskId',
                    title: '任务id',
                    visible: false
                },
                {
                    field: 'taskYear',
                    title: '年份'
                },
                {
                    field: 'taskName',
                    title: '任务名称'
                },
                {
                    field: 'contractClass',
                    title: '合同收支类别',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(contractClassDatas, value);
                    }
                },
                {
                    field: 'contractType',
                    title: '合同类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(contractTypeDatas, value);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                /*{
                    field: 'createBy',
                    title: '创建者'
                },*/
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                /*{
                    field: 'updateBy',
                    title: '更新者'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status == 1 || row.status == 2){
                            actions.push('<a class="btn btn-default btn-xs " href="javascript:void(0)" onclick="taskDetail(\'' + row.taskId + '\')"><i class="fa fa-info-circle"></i>详情</a> ');
                        }
                        if(row.status == 0 || row.status == 1){
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.taskId + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        }
                        if(row.status == 0){
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="taskBegin(\'' + row.taskId + '\')"><i class="fa fa-hourglass-start"></i>发布</a> ');
                        } else if(row.status == 1){
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="taskEnd(\'' + row.taskId + '\')"><i class="fa fa-hourglass-end"></i>结束</a> ');
                        }
                        /*actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.taskId + '\')"><i class="fa fa-remove"></i>删除</a>');*/

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function taskDetail(id) {
            alert("11111");
            /*$.post(prefix + "/changeContract", {id: id}, function (result) {
                if (result.code == web_status.SUCCESS) {
                    var url = ctx + "sale/csrcontract/editFour/" + id;
                    $.modal.openTab("销售合同备案", url)
                } else {
                    $.modal.msgError(result.msg);
                }
            });*/
        }

        // 发布评价任务
        function taskBegin(id) {
            $.modal.confirm("确认发布评价任务吗?", function() {
                $.post(prefix + "/taskBegin", {taskId: id}, function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("发布成功");
                        $.table.refresh();
                    } else {
                        $.modal.msgError(result.msg);
                    }
                });
            });
        }

        // 结束评价任务
        function taskEnd(id) {
            $.modal.confirm("确认结束评价任务吗?", function() {

                $.post(prefix + "/taskEnd", {taskId: id}, function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("操作成功，任务结束。");
                        $.table.refresh();
                    } else {
                        $.modal.msgError(result.msg);
                    }
                });
            });
        }

    </script>
</body>
</html>
